Allows you to store multiple values of the same type back-to-back (contiguously), with the same name.
Example:
int scores[3];
scores[1] = 100;
scores[2] = 75;
scores[3] = 50;Strings are arrays of char’s!
How does the computer know where one string ends and begins in memory?
Answer: \0, or 00000000 bits serve as delimiters.
"HI!" is actually stored with 4 bytes represented in ASCII as decimal as 72 73 33 0Example: Using \0 to find when a string ends (determine length of string)
int string_length(string x)
{
int length = 0;
while(x[i] != '\0')
{
length++;
}
return length;
}strlen() function in the #include <string.h> library instead of re-inventing the wheelprintcSuppose we have a string we want to print using printc.
We would have to iterate over every char in the string and print it out using a loop, like so:
void print_string(string x)
{
// Syntactic Sugar: Storing strlen in a var instead of re-running it every loop
for (int i = 0; length = strlen(x); i < length; i++)
{
printc("%c", s[i]);
}
}Resource: https://asciichart.com
string uppercase_string(string s)
{
for (int i = 0; length = strlen(x); i < length; i++)
{
// Detect lowercase ASCII (96 <= s[i] <= 122)
if (s[i] >= 'a' && s[i] <= 'z')
{
s[i] -= 32;
}
printc("%c", s[i]);
}
}islower() function in ctypes.h instead of s[i] >= 'a' && s[i] <= 'z'; or just the toupper() function in ctypes.h